﻿@model PageEditRolesData
@{
	string authClass = Model.SelectedAuthorized ? "" : "hidden";
	bool authRolesSelected = Model.SelectedRoles != null && Model.SelectedRoles.Count() > 0;
	
	var authAttrs = Model.IsEnabled ? null : new { disabled = "disabled" };
	Dictionary<string, object> authAllAttrs = new Dictionary<string, object>();
	Dictionary<string, object> authRolesAttrs = new Dictionary<string, object>();
	authAllAttrs.Add("id", "AuthAll");
	authRolesAttrs.Add("id", "AuthRoles");

	if (!Model.IsEnabled)
	{
		authAllAttrs.Add("disabled", "disabled");
		authRolesAttrs.Add("disabled", "disabled");
	}
}

@if (!Model.IsEnabled) {
	<div><b>К этой странице нельзая изменить доступ, т.к. это он установлен на более низком уровне.</b></div>
}
<label for="AllowAnonymous" class="checkbox">
	@Html.CheckBox("AllowAnonymous", Model.SelectedAnonymous, authAttrs)
	Разрешена для анонимных пользователей
</label>
<label for="AllowAuthorized" class="checkbox">
	@Html.CheckBox("AllowAuthorized", Model.SelectedAuthorized, authAttrs)
	Разрешена для авторизованных пользователей
</label>
<label for="AuthAll" class="checkbox auth @authClass">
	@Html.RadioButton("Auth", "", !authRolesSelected, authAllAttrs)
	Все авторизованные
</label>
<label for="AuthRoles" class="checkbox auth @authClass">
	@Html.RadioButton("Auth", "", authRolesSelected, authRolesAttrs)
	Роли:
</label>
@foreach (Role role in Model.Roles) {
	string roleId = "Role-" + role.Id;
	bool selected = Model.SelectedRoles != null && Model.SelectedRoles.Any(r => r.ToLower() == role.Name.ToLower());
		
	Dictionary<string, object> attrs = new Dictionary<string, object>();
	if (!Model.IsEnabled || !authRolesSelected)
	{
		attrs.Add("disabled", "disabled");
	}
	
	<label for="@roleId" class="checkbox role @authClass">
		@Html.CheckBox(roleId, selected, attrs)
		@role.Name
	</label>
}
